#include <nds.h>
#include <stdio.h>

#include "nanniWare.h"
#include "mumei.h"
#include "dracko.h"

#define DELAY 30

void splash(int bgTop, int bgSubTop, int bgBtm, void *function_ptr){

  void (*rotate)(int, s16, s16, s16, s16, s16, s16, s16, int);
  rotate = function_ptr;

  //23 Rows
  //31 Cols
  char wellcome[25];
  sprintf(wellcome, "%s", "                         ");

  int delayTime = 0;

  int xAxis = SCREEN_WIDTH / 2 - 64;
  int yAxis = SCREEN_HEIGHT / 2 - 64;

  int angleRotate = 0;

  int xPosition = -192;
  int yPosition = -192;

  int xScale = 1 << 10;
  int yScale = 1 << 10;

  dmaCopy(nanniWareBitmap, bgGetGfxPtr(bgTop), nanniWareBitmapLen);
  dmaCopy(mumeiBitmap, bgGetGfxPtr(bgBtm), mumeiBitmapLen);
  dmaCopy(drackoBitmap, bgGetGfxPtr(bgSubTop), drackoBitmapLen);

  while(1){

    scanKeys();
    int down = keysDown();

    if(delayTime >= DELAY && yScale == 1 << 8 && xScale == 1 << 8){
      if(strcmp(wellcome, "Touch the screen to start") != 0) sprintf(wellcome, "%s", "Touch the screen to start");
      else sprintf(wellcome, "%s", "                         ");
      iprintf("\x1b[%i;%iH%s", 13, 3, wellcome);
      delayTime = 0;
    }else delayTime += 1;

    if(yScale == 1 << 8 && xScale == 1 << 8) if(down & KEY_TOUCH){
      sprintf(wellcome, "%s", "                         ");
      iprintf("\x1b[%i;%iH%s", 13, 3, wellcome);
      break;
    }

    (*rotate)(bgSubTop, xAxis, yAxis, angleRotate, xScale, yScale, xPosition, yPosition, 2);

    if(yScale > 1 << 8) yScale -= 1 << 2;
    if(xScale > 1 << 8) xScale -= 1 << 2;

    if(xPosition < 0) xPosition += 1;
    if(yPosition < 0) yPosition += 1;

    swiWaitForVBlank();

  }

}